import type { DataTableColumns } from 'naive-ui'
import type { CreateColumsOptions } from '@/types/fcform'

export const createColums = ({ handDel, action }: CreateColumsOptions): DataTableColumns => {
  return [
    {
      title: '类型',
      key: 'dictType',
    },
    {
      title: '数据值',
      key: 'itemValue',
    },
    {
      title: '标签名',
      key: 'label',
    },
    {
      title: '描述',
      key: 'description',
    },
    {
      title: '排序',
      key: 'sortOrder',
    },
    {
      title: '备注',
      key: 'remarks',
    },
    {
      title: '操作',
      key: 'total',
      align: 'center',
      width: 120,
      render(row) {
        const arr = []
        const editBtn = fastUnit.createBtn('编辑', {
          type: 'warning',
          onClick: () => action.default(row),
        })
        const delBtn = fastUnit.createBtn('删除', {
          type: 'error',
          onClick: () => handDel(row),
        })
        if (commonUnit.auth('sys_dict_edit')) {
          arr.push(editBtn)
        }
        if (commonUnit.auth('sys_dict_del')) {
          arr.push(delBtn)
        }
        return h('div', arr)
      },
    },
  ]
}
